package com.cn.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: SessionDemo02
 * @Description:
 * @author: RZS
 * @date: 2022/4/14  14:40
 */
@WebServlet("/sd2.do")
public class SessionDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取session对象
        HttpSession session = request.getSession();
        // 设置session失效时间
        session.setMaxInactiveInterval(60*3);

        // 绑定数据到session域中
        session.setAttribute("tiem", System.currentTimeMillis());
        session.setAttribute("username", "张三");

    }
}
